from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-22 14:02:15.595007
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 22, Jul, 2022
Time: 14:02:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.8861
Nobs: 725.000 HQIC: -50.2357
Log likelihood: 9121.52 FPE: 1.22318e-22
AIC: -50.4554 Det(Omega_mle): 1.08130e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299683 0.056908 5.266 0.000
L1.Burgenland 0.107284 0.037276 2.878 0.004
L1.Kärnten -0.107101 0.019767 -5.418 0.000
L1.Niederösterreich 0.209159 0.078113 2.678 0.007
L1.Oberösterreich 0.106931 0.076163 1.404 0.160
L1.Salzburg 0.253786 0.039878 6.364 0.000
L1.Steiermark 0.042620 0.052031 0.819 0.413
L1.Tirol 0.108608 0.042209 2.573 0.010
L1.Vorarlberg -0.063116 0.036438 -1.732 0.083
L1.Wien 0.047309 0.067338 0.703 0.482
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054847 0.118927 0.461 0.645
L1.Burgenland -0.031450 0.077901 -0.404 0.686
L1.Kärnten 0.047086 0.041309 1.140 0.254
L1.Niederösterreich -0.178546 0.163242 -1.094 0.274
L1.Oberösterreich 0.411348 0.159168 2.584 0.010
L1.Salzburg 0.288282 0.083338 3.459 0.001
L1.Steiermark 0.107344 0.108735 0.987 0.324
L1.Tirol 0.311364 0.088210 3.530 0.000
L1.Vorarlberg 0.026005 0.076148 0.342 0.733
L1.Wien -0.029056 0.140725 -0.206 0.836
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188458 0.029064 6.484 0.000
L1.Burgenland 0.090264 0.019038 4.741 0.000
L1.Kärnten -0.008804 0.010095 -0.872 0.383
L1.Niederösterreich 0.263853 0.039894 6.614 0.000
L1.Oberösterreich 0.136755 0.038898 3.516 0.000
L1.Salzburg 0.045818 0.020367 2.250 0.024
L1.Steiermark 0.020889 0.026573 0.786 0.432
L1.Tirol 0.092752 0.021557 4.303 0.000
L1.Vorarlberg 0.056618 0.018610 3.042 0.002
L1.Wien 0.114568 0.034391 3.331 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111516 0.029615 3.765 0.000
L1.Burgenland 0.045752 0.019399 2.358 0.018
L1.Kärnten -0.013897 0.010287 -1.351 0.177
L1.Niederösterreich 0.189605 0.040651 4.664 0.000
L1.Oberösterreich 0.301486 0.039636 7.606 0.000
L1.Salzburg 0.109455 0.020753 5.274 0.000
L1.Steiermark 0.104471 0.027077 3.858 0.000
L1.Tirol 0.105363 0.021966 4.797 0.000
L1.Vorarlberg 0.068219 0.018962 3.598 0.000
L1.Wien -0.022572 0.035043 -0.644 0.520
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130623 0.053984 2.420 0.016
L1.Burgenland -0.049634 0.035362 -1.404 0.160
L1.Kärnten -0.040829 0.018751 -2.177 0.029
L1.Niederösterreich 0.165737 0.074100 2.237 0.025
L1.Oberösterreich 0.140846 0.072251 1.949 0.051
L1.Salzburg 0.288967 0.037829 7.639 0.000
L1.Steiermark 0.036321 0.049358 0.736 0.462
L1.Tirol 0.163115 0.040041 4.074 0.000
L1.Vorarlberg 0.099329 0.034566 2.874 0.004
L1.Wien 0.067819 0.063879 1.062 0.288
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055712 0.042938 1.297 0.194
L1.Burgenland 0.039373 0.028126 1.400 0.162
L1.Kärnten 0.051351 0.014914 3.443 0.001
L1.Niederösterreich 0.218354 0.058938 3.705 0.000
L1.Oberösterreich 0.295904 0.057467 5.149 0.000
L1.Salzburg 0.043645 0.030089 1.451 0.147
L1.Steiermark 0.001222 0.039258 0.031 0.975
L1.Tirol 0.142478 0.031848 4.474 0.000
L1.Vorarlberg 0.072481 0.027493 2.636 0.008
L1.Wien 0.080310 0.050808 1.581 0.114
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175761 0.051304 3.426 0.001
L1.Burgenland -0.002714 0.033606 -0.081 0.936
L1.Kärnten -0.062561 0.017820 -3.511 0.000
L1.Niederösterreich -0.081518 0.070421 -1.158 0.247
L1.Oberösterreich 0.192040 0.068664 2.797 0.005
L1.Salzburg 0.057861 0.035951 1.609 0.108
L1.Steiermark 0.235549 0.046907 5.022 0.000
L1.Tirol 0.498170 0.038053 13.092 0.000
L1.Vorarlberg 0.044521 0.032850 1.355 0.175
L1.Wien -0.054680 0.060707 -0.901 0.368
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174312 0.058888 2.960 0.003
L1.Burgenland -0.006667 0.038574 -0.173 0.863
L1.Kärnten 0.066236 0.020455 3.238 0.001
L1.Niederösterreich 0.207092 0.080831 2.562 0.010
L1.Oberösterreich -0.073983 0.078814 -0.939 0.348
L1.Salzburg 0.207411 0.041265 5.026 0.000
L1.Steiermark 0.122761 0.053841 2.280 0.023
L1.Tirol 0.070772 0.043678 1.620 0.105
L1.Vorarlberg 0.116121 0.037706 3.080 0.002
L1.Wien 0.118308 0.069682 1.698 0.090
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.361864 0.033971 10.652 0.000
L1.Burgenland 0.007355 0.022252 0.331 0.741
L1.Kärnten -0.023759 0.011800 -2.014 0.044
L1.Niederösterreich 0.217688 0.046629 4.668 0.000
L1.Oberösterreich 0.199130 0.045465 4.380 0.000
L1.Salzburg 0.042832 0.023805 1.799 0.072
L1.Steiermark -0.014109 0.031059 -0.454 0.650
L1.Tirol 0.104874 0.025197 4.162 0.000
L1.Vorarlberg 0.070072 0.021751 3.222 0.001
L1.Wien 0.036192 0.040197 0.900 0.368
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039962 0.138522 0.191206 0.150633 0.117397 0.102865 0.061925 0.215542
Kärnten 0.039962 1.000000 -0.006545 0.132663 0.038870 0.094598 0.433678 -0.053691 0.098085
Niederösterreich 0.138522 -0.006545 1.000000 0.334961 0.141624 0.293695 0.095115 0.175423 0.314169
Oberösterreich 0.191206 0.132663 0.334961 1.000000 0.227871 0.324836 0.175218 0.163787 0.261117
Salzburg 0.150633 0.038870 0.141624 0.227871 1.000000 0.142132 0.111472 0.143788 0.123481
Steiermark 0.117397 0.094598 0.293695 0.324836 0.142132 1.000000 0.145901 0.136892 0.070913
Tirol 0.102865 0.433678 0.095115 0.175218 0.111472 0.145901 1.000000 0.110564 0.142165
Vorarlberg 0.061925 -0.053691 0.175423 0.163787 0.143788 0.136892 0.110564 1.000000 -0.002155
Wien 0.215542 0.098085 0.314169 0.261117 0.123481 0.070913 0.142165 -0.002155 1.000000